package com.lp.biz.operations.controller;

import com.lp.biz.operations.model.vo.CategoryAdd;
import com.lp.biz.operations.service.CategoryService;
import com.lp.common.annotation.PermissionAnnotation;
import com.lp.common.entity.PageParams;
import com.lp.common.utils.CommonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import static com.lp.common.constant.MenuConstant.CATEGORY_RECOMMEND;

/**
 * @program: backend
 * @description:
 * @author: Ke.Song
 * @since: 2024-07-18 21:01:14
 */
@RestController
@RequestMapping("/category")
public class CategoryController {

    @Autowired
    private CategoryService categoryService;

    /**
     * 获取分类推荐内容列表
     * @return 查询结果
     */
    @GetMapping()
    @PermissionAnnotation(menus = {CATEGORY_RECOMMEND})
    public CommonResult getContentList(PageParams query) {
        return categoryService.getContentList(query);
    }

    /**
     * 添加分类推荐
     * @param params 添加参数
     * @return 处理结果
     */
    @PostMapping()
    @PermissionAnnotation(menus = {CATEGORY_RECOMMEND})
    public CommonResult addRecommend(@RequestBody@Validated CategoryAdd params) {
        categoryService.addRecommend(params);
        return CommonResult.success();
    }

    /**
     * 删除分类推荐
     * @param contentId 内容Id
     * @return 处理结果
     */
    @DeleteMapping("/{contentId}")
    @PermissionAnnotation(menus = {CATEGORY_RECOMMEND})
    public CommonResult deleteCategoryRecommend(@PathVariable Integer contentId) {
        categoryService.deleteCategoryRecommend(contentId);
        return CommonResult.success();
    }
}
